package com.fjwt.gz.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjwt.gz.components.mq.model.ExportExcelMQ;
import com.fjwt.gz.components.mq.vender.IMQSender;
import com.fjwt.gz.core.constants.Constants;
import com.fjwt.gz.core.exception.BizException;
import com.fjwt.gz.core.model.security.GzUserDetails;
import com.fjwt.gz.db.dto.ActivityAwardDTO;
import com.fjwt.gz.db.entity.StatActe017NumEntity;
import com.fjwt.gz.db.entity.StatActe017RecordEntity;
import com.fjwt.gz.db.vo.StatActe017RecordVO;
import com.fjwt.gz.service.mapper.StatActe017RecordMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * ACTE017越减越便宜活动--用户参与记录明细 服务实现类
 * </p>
 *
 * @author shiyonghao
 * @since 2025-07-24
 */
@Slf4j
@Service
public class StatActe017RecordService extends ServiceImpl<StatActe017RecordMapper, StatActe017RecordEntity> {

    @Autowired
    private StatActe017RecordMapper statActe017RecordMapper;

    @Autowired
    private SysExportTaskService sysExportTaskService;
    @Autowired
    private IMQSender mqSender;

    public IPage<StatActe017NumEntity> getStatActe017Num(Page page) {
        return this.baseMapper.getStatActe017Num(page);
    }

    /**
     * 越减越便宜客户参与记录明细 查询
     *
     * @param iPage
     * @param activityAwardDTO
     * @return
     */
    public IPage<StatActe017RecordVO> getFansRecord(IPage iPage, ActivityAwardDTO activityAwardDTO) {
        return this.statActe017RecordMapper.getFansRecord(iPage, activityAwardDTO);
    }

    /**
     * 越减越便宜客户参与记录明细 导出
     *
     * @param activityAwardDTO
     * @return
     */
    public void exportFansRecord(ActivityAwardDTO activityAwardDTO) {
        String fileName = "越减越便宜客户参与记录明细表--截至" + DateUtil.format(new Date(), DatePattern.CHINESE_DATE_PATTERN);
        // 添加导出任务记录
        this.sysExportTaskService.addExportTask(
                GzUserDetails.getCurrentUserDetails().getSysUser(),
                fileName,
                Constants.EXPORT_TASK_ENUM.REQUEST_CODE.FANS_PARTICIPATION_RECORD,
                Constants.EXPORT_TASK_ENUM.RESOURCE_TYPE.FANS,
                JSONUtil.toJsonStr(activityAwardDTO)
        );
    }

}
